$(function(){
	var param = $("#tabContent > .tab-pane.active").data();
	loadCase();
	function loadCase() {
	var tb_id='tb'+new Date().getTime();
	$('#'+tabId+' #content').html('<table class="stripe cc table" style="width:100%;"  id="'+tb_id+'"'
		 		   +'style="text-align: center;">'     //transition:all .2s;
		 		  +'<thead><tr>'
		 		 +'<td style="width:80px">病案号</td>'
		 		+'<td width="80px">姓名</td>'
		 		+'<td width="40px">性别</td>'
		 		+'<td width="40px">年龄</td>'
		 		+'<td width="100px">入院时间</td>'
		 		+'<td width="100px">出院时间</td>'
		 		+'<td width="100px">出院科室</td>'
		 		+'<td width="40px">住院日</td>'
		 		+'<td width="80px">总费用(元)</td>'
		 		+'<td width="200px">主诊断</td>'
		 		+'<td width="80px">DRG代码</td>'
		 		+'<td width="200px">次均费用(标杆)</td>'
		 		+'</tr></thead><tbody id="table"></tbody></table>');
		loadPageData(tb_id);
	}
	function loadPageData(tb_id){
		$.post(contextPath + "/order/getCases.dhc", param).done(function(data){
			var columns=[ 
							{ "data": "mrNo",
								"render": function(obj, type, full){
									var mrNo = full.mrNo;
								return "<a href=\"javascript:medicalRecord('"+full.id+"','"+full.patientName+"')\">"+mrNo+"</a>";
							}},
							 { "data": "patientName" },
							 { "data": "sex",
								 "render": function(obj, type, full) {
							               var sex=full.sex;
							               if(sex == "1"){
							              	 sex = "男";
							               }else if(sex == "2"){
							              	 sex = "女";
							               }else{
							              	 sex = "未知";
							               }
							               return sex;
							           }
							 },
							 { "data": "ageYear" ,
							   "render": function(obj, type, full) {
								   if(full.ageYear>0){
									   return full.ageYear;
								   } else if(full.ageMonth>0){
									   return full.ageMonth + '月';
								   } else if(full.ageDays>0){
									   return full.ageDays + '天';
								   } else if(full.newbornDays>0){
									   return full.newbornDays + '天';
								   }
					           }
							 },
							 { "data": "inDate"},
							 { "data": "outDate",
								 "render": function(obj, type, full) {
							               return full.outDate;
							           }
							  },
							 { "data": "outDep" },
							 { "data": "inDays" },
							 { "data": "costamount", 
								 "render": function(obj, type, full) {
									 if(full.benchmark>0 && full.costamount>1*full.benchmark)//超过标杆值
						               return "<font color='red'>"+full.costamount+"</font>";
									 else
										return full.costamount;
						           }
							 },
							 { "data": "diagnoseDessmain" },
							 { "data": "drgCode" },
							 { "data": "avgFeeStd" }
							];
			var paramsDataTables={ordering:false,lengthMenu:[[ 50,100,500, 1000,99999],[ 50,100,500, 1000,'全部']]};
			$('#'+tabId+' #'+tb_id).dataTableBasic(columns,data.data,paramsDataTables);
		});
	}
})

